package com.analy.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.analy.service.WorkService;
import com.api.service.AnalyService;
import com.api.service.ManageService;
import com.common.system.SystemData;
import com.common.utils.JsonUtil;
import com.common.vo.SnatchItem;
import com.common.vo.SnatchTask;
import com.common.vo.WebConfig;
@Service
public class AnalyServiceImpl implements AnalyService {
	
	@Autowired
	WorkService workService;
	
	@Autowired
	ManageService manageService;
	
	@Override
	public int analyTask(String webCode, String gameCode, String itemName,
			String itemType, int status) {
		if(null == webCode || null == gameCode || null == itemName || null == itemType){
			return -1;
		}
		SnatchItem snatchItem = SystemData.findSnatchItem(webCode, gameCode, itemName, itemType);
		if(null == snatchItem) return -2;
		 SnatchTask snatchTask = new SnatchTask();
		 snatchTask.setValid(status);
		 snatchTask.setWebCode(webCode);
		 snatchTask.setGameCode(gameCode);
		 snatchTask.setSleepTiem(snatchItem.getSleepTiem());
		 snatchTask.setItemName(snatchItem.getItemName());
		 snatchTask.setItemType(snatchItem.getItemType());
		 snatchTask.setRatioType(snatchItem.getRatioType());
		 snatchTask.setTaskCode(webCode+"_"+gameCode+"_"+itemName+"_"+itemType);
		 return workService.analyTask(snatchTask, snatchItem);
	}

	@Override
	public int manageConfig(WebConfig config) {
		String jsonString = JsonUtil.toJSONString(config);
		
		return 0;
	}

	@Override
	public int register(WebConfig config) {
		String jsonString = JsonUtil.toJSONString(config);
		return manageService.registerNode(jsonString);
	}
	

}
